package edu.pku.sei.modeler.figures;

import org.eclipse.draw2d.geometry.Rectangle;

public abstract class InteractionFragmentFigure extends CommonFigure {
	// TODO Put this method is an interface somewhere (formerly
	// InteractionFragmentFigure)
	public Rectangle getPreferredModelBounds(final Rectangle bounds,
			final Rectangle coveredBounds) {
		if (coveredBounds != null) {
			int prefx = coveredBounds.x + coveredBounds.width / 2;
			int prefy;
			if (bounds.y < coveredBounds.y + LifelineFigure.HEAD_HEIGHT)
				prefy = coveredBounds.y + LifelineFigure.HEAD_HEIGHT;
			else if (bounds.bottom() > coveredBounds.bottom())
				prefy = coveredBounds.bottom() - bounds.height;
			else
				prefy = bounds.y;
			return new Rectangle(prefx, prefy, 1, 1);
		} else
			return bounds.getCopy();
	}

	public Rectangle getPreferredFigureBounds(final Rectangle bounds,
			final Rectangle coveredBounds) {
		return getPreferredModelBounds(bounds, coveredBounds);
	}

}
